import { message } from 'antd';
import api from '../../api';
export default {
  namespace: 'fundManageNewM',
  state: {
    dictMap: {},
    findPermission: {},
    list: {
      data: [],
      pagination: {},
    },
  },
  effects: {
    // 查询资金列表
    *fetch({ payload, callback }, { call, put }) {
      const response = yield call(api.fundManageNew.getList, payload);
      if (response && response.success) {
        yield put({
          type: 'save',
          payload: {
            list: {
              data: response.data,
              pagination: {
                current: response.current,
                pageSize: response.pageSize,
                total: response.total,
              },
            },
          },
        });
        if (callback) {
          callback(response.data);
        }
      } else {
        message.error('列表查询失败');
      }
    },
    // 资金调拨：一个减 一个加
    *transfer({ payload }, { call }) {
      const response = yield call(api.fundManageNew.transfer, payload);
      return response;
    },
    // 资金操作
    *operation({ payload }, { call }) {
      const response = yield call(api.fundManageNew.operation, payload);
      return response;
    },
    // 保证金管理
    *operationBzj({ payload }, { call }) {
      const response = yield call(api.fundManageNew.operationBzj, payload);
      return response;
    },
    // 批量查询
    *fetchDict({ payload }, { call, put }) {
      const response = yield call(api.fundManageNew.queryDictByKeys, payload);
      if (response && response.success) {
        yield put({
          type: 'save',
          payload: {
            dictMap: response.data,
          },
        });
      } else {
        message.error('查询数据字典失败');
      }
    },
    // 组合权限查询
    *findPermission({ payload }, { call, put }) {
      const response = yield call(api.fundManageNew.findPermission, payload);
      if (response && response.code == 0) {
        yield put({
          type: 'save',
          payload: {
            findPermission: response.data.dataSource,
          },
        });
        return response.data.dataSource;
      } else {
        message.error('查询组合权限失败');
      }
    },
  },
  reducers: {
    save(state, { payload }) {
      return { ...state, ...payload };
    },
  },
};
